package com.pn.mapper;

import com.github.pagehelper.Page;
import com.pn.entity.*;
import com.pn.utils.Result;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductMapper {

    //查询商品分类树
    @Select("select * from product_type")
    List<ProductType> productTypeTree();


    //商品列表展示
    Page<Product> productPageList(Product product);

    //根据型号查询商品数据
    @Select("select * from product where product_num = #{productMum}")
    Product findProductByNum(String productMum);

    //添加商品
    public int insertProduct(Product product);

    //商品上下架
    @Update("update product set up_down_state = #{upDownState} where product_id = #{productId}")
    int changeProductStateBId(@Param("productId") Integer productId,@Param("upDownState") String upDownState);

    //根据productId查询商品
    List<Product> productSelectByIds(List<Integer> ids);

    //根据ids 批量删除商品
    void productRemoveByids(List<Integer> ids);

    //根据productId删除商品
    @Delete("delete from product where product_id = #{productId}")
    void deleteProductById(Integer productId);

    //根据brandName查找branId
    @Select("select brand_id from brand where brand_name = #{brandName}")
    Integer SelectBrandByName(String brandName);

    //根据typeName查找typeId
    @Select("select type_id from product_type where type_name = #{typeName}")
    Integer SelectTypeByName(String typeName);

    //根据supplyName查找supplyId
    @Select("select supply_id from supply where supply_name = #{supplyName}")
    Integer SelectSupplyByName(String supplyName);

    //根据placeName查找placeId
    @Select("select place_id from place where place_name = #{placeName}")
    Integer SelectPlaceByName(String placeName);

    //根据unitName查找unitId
    @Select("select unit_id from unit where unit_name = #{unitName}")
    Integer SelectUnitByName(String unitName);

    //删除商品分类
    @Delete("delete from product_type where type_id=#{param1} or parent_id =#{param2}")
    int deleteTypeByTidOrPid(Integer typeId, Integer parentId);

    //修改商品分类
    int typeUpdate(ProductType productType);

    //根据商品id查询商品的库存
    @Select("select product_invent from product where product_id = #{productId}")
    int findInventById(Integer productId);

}
